package com.example.animations;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.animations.activities.ColorAnimationActivity;
import com.example.animations.activities.GeometryEffectActivity;
import com.example.animations.activities.LongListActivity;
import com.example.animations.activities.OrientationChangeActivity;
import com.example.animations.activities.OrientationChangeWRActivity;
import com.example.animations.activities.PathAnimationActivity;
import com.example.animations.activities.PresentedActivity;
import com.example.animations.activities.PushedActivity;
import com.example.animations.activities.RTAnimationActivity;
import com.example.animations.activities.TextAnimationActivity;
import com.example.animations.activities.TransitionsActivity;
import com.example.animations.adapters.MainListAdapter;
import com.example.animations.dialogs.MainDialog;
import com.example.animations.models.MainMenuItem;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    private final List<MainMenuItem> _items = Arrays.asList(
            new MainMenuItem("Animations", MainMenuItem.MainActionType.NONE),
            new MainMenuItem("Text Animation", MainMenuItem.MainActionType.TEXT_ANIMATIONS),
            new MainMenuItem("Color Animation", MainMenuItem.MainActionType.COLOR_ANIMATIONS),
            new MainMenuItem("Path Animation", MainMenuItem.MainActionType.PATH_ANIMATIONS),
            new MainMenuItem("Geometry Effect", MainMenuItem.MainActionType.GEOMETRY_EFFECT),

            new MainMenuItem("Transitions", MainMenuItem.MainActionType.NONE),
            new MainMenuItem("Transitions", MainMenuItem.MainActionType.TRANSITIONS),

            new MainMenuItem("Navigation", MainMenuItem.MainActionType.NONE),
            new MainMenuItem("Push View", MainMenuItem.MainActionType.PUSH_VIEW),
            new MainMenuItem("Present View", MainMenuItem.MainActionType.PRESENT_VIEW),
            new MainMenuItem("Show Alert", MainMenuItem.MainActionType.SHOW_ALERT),
            new MainMenuItem("Call 123-45-67", MainMenuItem.MainActionType.MAKE_A_CALL),
            new MainMenuItem("Open Browser", MainMenuItem.MainActionType.OPEN_BROWSER),

            new MainMenuItem("Others", MainMenuItem.MainActionType.NONE),
            new MainMenuItem("Long List", MainMenuItem.MainActionType.LONG_LIST),
            new MainMenuItem("Orientation Change", MainMenuItem.MainActionType.ORIENTATION_CHANGE),
            new MainMenuItem("Orientation Change (without recreating)", MainMenuItem.MainActionType.ORIENTATION_CHANGE_WR),
            new MainMenuItem("RenderThread Animations", MainMenuItem.MainActionType.RT_ANIMATION)
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = findViewById(R.id.main_list);
        listView.setAdapter(new MainListAdapter(this, _items));
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        MainMenuItem item = _items.get(i);

        switch (item.getActionType()) {
            case TEXT_ANIMATIONS:
                openTextAnimations();
                break;
            case COLOR_ANIMATIONS:
                openColorAnimations();
                break;
            case PATH_ANIMATIONS:
                openPathAnimations();
                break;
            case GEOMETRY_EFFECT:
                openGeometryEffect();
                break;
            case TRANSITIONS:
                openTransitions();
                break;
            case PUSH_VIEW:
                pushView();
                break;
            case PRESENT_VIEW:
                presentView();
                break;
            case SHOW_ALERT:
                showAlert();
                break;
            case MAKE_A_CALL:
                makeCall();
                break;
            case OPEN_BROWSER:
                openBrowser();
                break;
            case LONG_LIST:
                openLongList();
                break;
            case ORIENTATION_CHANGE:
                openOrientationChange();
                break;
            case ORIENTATION_CHANGE_WR:
                openOrientationChangeWR();
                break;
            case RT_ANIMATION:
                openRTAnimation();
                break;
            case NONE:
            default:
                break;
        }
    }

    private void openTextAnimations() {
        Intent intent = new Intent(this, TextAnimationActivity.class);
        startActivity(intent);
    }

    private void openColorAnimations() {
        Intent intent = new Intent(this, ColorAnimationActivity.class);
        startActivity(intent);
    }

    private void openPathAnimations() {
        Intent intent = new Intent(this, PathAnimationActivity.class);
        startActivity(intent);
    }

    private void openGeometryEffect() {
        Intent intent = new Intent(this, GeometryEffectActivity.class);
        startActivity(intent);
    }

    private void openTransitions() {
        Intent intent = new Intent(this, TransitionsActivity.class);
        startActivity(intent);
    }

    private void pushView() {
        Intent intent = new Intent(this, PushedActivity.class);
        startActivity(intent);
    }

    private void presentView() {
        Intent intent = new Intent(this, PresentedActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.slide_up_show, R.anim.slide_down_hide_10);
    }

    private void showAlert() {
        MainDialog dialog = new MainDialog(this);
        dialog.show();
    }

    private void makeCall() {
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:123-45-67"));
        startActivity(intent);
    }

    private void openBrowser() {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
        startActivity(intent);
    }

    private void openLongList() {
        Intent intent = new Intent(this, LongListActivity.class);
        startActivity(intent);
    }

    private void openOrientationChange() {
        Intent intent = new Intent(this, OrientationChangeActivity.class);
        startActivity(intent);
    }

    private void openOrientationChangeWR() {
        Intent intent = new Intent(this, OrientationChangeWRActivity.class);
        startActivity(intent);
    }

    private void openRTAnimation() {
        Intent intent = new Intent(this, RTAnimationActivity.class);
        startActivity(intent);
    }
}